package algorithm;

public class T00169 {
    public static void main(String[] args) {
        int[] nums = {1,2,1,2,2};
        System.out.println(new Solution().majorityElement(nums));
    }

    static class Solution {
        public int majorityElement(int[] nums) {
            int majority = Integer.MIN_VALUE;
            int count = 0;
            for (int i = 0; i < nums.length; i ++) {
                if (count == 0) {
                    majority = nums[i];
                }
                count += nums[i] == majority ? 1 : -1;
            }
            return majority;
        }
    }
}
